<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>04-仿京东案例</title>
    <style>
        .box {
            position: relative;
            width: 400px;
            border-bottom:1px solid #ccc;
            margin :100px auto;
        }
        .box input {
            width: 370px;
            height: 30px;
            border:0;
            outline: none;
        }
        .box img {
            position: absolute;
            top:2px;
            right:2px;
            width:24px;
        }
    </style>
</head>
<body>
    <div class="box">
        <label for="">
            <img src="./images/close.png" alt="">
        </label>
        <input type="password" name="" id="">
    </div>
    
    <script>
        // 点击图片，图片 src 变化，表单类型变化。

        let img = document.querySelector('img');
        let input = document.querySelector('input');
        let flag = true;   // 标识符  close
        // let flag = false;
        // console.log(flag);
            img.onclick = function(){
            if(flag){
                flag = false;
                img.src = 'images/open.png';
                input.type = 'text';
                // input.style.backgroundColor = 'yellow' ;

            } else{
                flag = true;
                img.src = 'images/close.png';
                input.type = 'password';
                // input.style.backgroundColor = 'red' ;

            }
        } 


        
        // huo'ze
  /*     let flag = true;
        img.onclick = function () {
            if (flag) {
                img.src = "images/open.png";
                input.type = "text";
            } else {
                img.src = "images/close.png";
                input.type = "password";
            }
            flag = !flag;
        } */
    </script>
</body>
</html>
